﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Drawing;
using System.Data;
using System.Text;
using System.Windows.Forms;
using Pahan.McuFusion.Common;
using Pahan.McuFusion.UI.Interfaces.NewWorkspaceWizardPages;

namespace Pahan.McuFusion.UI.Views.NewWorkspaceWizardPages
{
    public partial class ProgrammerPage : UserControl, IProgrammerPage
    {
        public ProgrammerPage()
        {
            InitializeComponent();
        }

        #region Implementation of IWizardPage

        /// <summary>
        /// Gets the title of the page.
        /// </summary>
        public string Title
        {
            get
            {
                return "Programmer && MCU";
            }
        }

        #endregion

        #region Implementation of IProgrammerPage

        /// <summary>
        /// Shows the list of the available programmers.
        /// </summary>
        public void ShowProgrammers(IList<ProgrammerInfo> programmers)
        {
            lstProgrammers.DataSource = programmers;
            if (programmers.Count > 0)
            {
                lstProgrammers.SelectedIndex = 0;
            }
        }

        /// <summary>
        /// Shows the list of the available microcontrollers.
        /// </summary>
        public void ShowMicrocontrollers(IList<DeviceInfo> mcus)
        {
            lstMicrocontrollers.DataSource = mcus;
            if (mcus.Count > 0)
            {
                lstMicrocontrollers.SelectedIndex = 0;
            }
        }

        /// <summary>
        /// Gets the selected programmer.
        /// </summary>
        public ProgrammerInfo SelectedProgrammer
        {
            get
            {
                return lstProgrammers.SelectedItem as ProgrammerInfo;
            }
        }

        /// <summary>
        /// Gets the selected MCU.
        /// </summary>
        public DeviceInfo SelectedMicrocontroller
        {
            get
            {
                return lstMicrocontrollers.SelectedItem as DeviceInfo;
            }
        }

        public event EventHandler SelectedProgrammerChanged;

        public event EventHandler SelectedMicrocontrollerChanged;

        #endregion

        private void OnProgrammerChanged(object sender, EventArgs e)
        {
            var handler = SelectedProgrammerChanged;
            if (handler != null)
            {
                handler(this, e);
            }
        }

        private void OnMcuChanged(object sender, EventArgs e)
        {
            var handler = SelectedMicrocontrollerChanged;
            if (handler != null)
            {
                handler(this, e);
            }
        }
    }
}
